*Tabels and figures

clear all
capture log close
set more off

global rawdata = "D:\Data\Workdata\706991\Hours2023\rawdata"
global workdata = "D:\Data\Workdata\706991\Hours2023\workdata"
global output "D:\Data\Workdata\706991\Hours2023\output"

use "$workdata\regression_data_full1", clear

global covars = "woman age age_sq exp exp_sq tenure tenure_sq kvu mvu lvu partner oldest_child02 oldest_child34 oldest_child5 private ib1996.year i.industry i.disco2 export_pos sales firm_size"

********************************************************************************
*	TABLE 1: Occupational classification in the DLFS and IDA data
********************************************************************************
use "$workdata\regression_data_full1", clear
tab pos
tab pos if pos <= 2
tab pos woman	

use "$workdata\data_RAS_full", clear
keep if aar >= 1996 & aar <= 2018
merge 1:1 pnr aar using "$workdata\data_personer_full"
keep if _m == 3
tab pos
tab pos if pos <= 2
tab pos woman
tab pos if pos <= 2

********************************************************************************
*	TABLE 2: Summary statistics
********************************************************************************
keep if pos <= 2

gen cat1 = 1 if pos == 1					//if Executive
gen cat2 = 1 if pos == 2 & prom1 == 1		//if prom from manager to executive
gen cat3 = 1 if pos == 2 & prom1 != 1		//if manager and no promoton

sum age exp tenure woman partner num_children hs_less kvu mvu lvu 
sum age exp tenure woman partner num_children hs_less kvu mvu lvu if cat1 == 1
sum age exp tenure woman partner num_children hs_less kvu mvu lvu if cat2 == 1
sum age exp tenure woman partner num_children hs_less kvu mvu lvu if cat3 == 1

********************************************************************************
*	TABLE 3: Working hours: Top Managers, and Managers with and without top management appointments
********************************************************************************
gen prop40a = (h_actual>=40)
gen prop50a = (h_actual>=50)
gen prop60a = (h_actual>=60)

gen prop40u = (h_usual>=40)
gen prop50u = (h_usual>=50)
gen prop60u = (h_usual>=60)

forvalues i = 1/3 {
	sum h_actual if cat`i' == 1
	sum ha37 if cat`i' == 1
	sum prop40a if cat`i' == 1
	sum prop50a if cat`i' == 1
	sum prop60a if cat`i' == 1
}

forvalues i = 1/3 {
	sum h_usual if cat`i' == 1
	sum hu37 if cat`i' == 1
	sum prop40u if cat`i' == 1
	sum prop50u if cat`i' == 1
	sum prop60u if cat`i' == 1
}

*Promotion and hours by gender
tab prom1 if pos == 2
bys woman: tab prom1 if pos == 2

preserve
keep if woman == 0 & pos == 2
sum h_actual h_usual
sum prop50a prop50u
restore

preserve
keep if woman == 1 & pos == 2
sum h_actual h_usual
sum prop50a prop50u
restore

********************************************************************************
*	TABLE 4: Top management appointment and hours
********************************************************************************

qui logit prom1 h2a $covars if (pos == 2), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table 4.xls", dec(4) replace 

qui logit prom1 ha0_36 ha38_47 hagt48 $covars if (pos == 2), robust
test ha38_47 = hagt48
margins, dydx (h*) post
outreg2 h* using "$output/Table 4.xls", dec(4) 

qui logit prom1 h2u $covars if (pos == 2), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table 4.xls", dec(4) 

qui logit prom1 hu0_36 hu38_47 hugt48 $covars if (pos == 2), robust
test hu38_47 = hugt48 
margins, dydx (h*) post
outreg2 h* using "$output/Table 4.xls", dec(4) 


********************************************************************************
*	TABLE 5: Robustness checks
********************************************************************************

*single observation
use "$rawdata\idan.dta", clear
keep job_type aar pnr
destring *, replace
drop if job_type == ""
bys pnr aar: gen obs_per_year = _N
bys pnr aar: gen xx = _n
keep if xx == 1
drop xx job
rename aar year 
sort pnr year
save "$workdata\data_obs_per_year", replace

use "$workdata\regression_data_full1", clear
merge 1:1 pnr year using "$workdata\data_obs_per_year"
keep if _m == 3
codebook pnr if pos == 2 & obs_per_year == 1
keep if obs_per_year == 1

qui logit prom1 h2a $covars if (pos == 2), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table robust.xls", dec(4) 

qui logit prom1 ha0_36 ha38_47 hagt48 $covars if (pos == 2), robust
margins, dydx (h*) post
outreg2 h* using "$output/Table robust.xls", dec(4) 

qui logit prom1 h2u $covars if (pos == 2), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table robust.xls", dec(4) 

qui logit prom1 hu0_36 hu38_47 hugt48 $covars if (pos == 2), robust
margins, dydx (h*) post
outreg2 h* using "$output/Table robust.xls", dec(4) 

*weighted
use "$workdata\regression_data_full1", clear
gen month = (round(refweek/4))
gen abs_distance = (abs(month - 11)) 
gen distance = 11 - abs_distance

qui logit prom1 h2a $covars [iweight=distance] if (pos == 2), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table 5.xls", dec(4) replace 

qui logit prom1 ha0_36 ha38_47 hagt48 $covars [iweight=distance] if (pos == 2), robust
margins, dydx (h*) post
outreg2 h* using "$output/Table 5.xls", dec(4) 

qui logit prom1 h2u $covars [iweight=distance] if (pos == 2), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table 5.xls", dec(4) 

qui logit prom1 hu0_36 hu38_47 hugt48 $covars [iweight=distance] if (pos == 2), robust
margins, dydx (h*) post
outreg2 h* using "$output/Table 5.xls", dec(4) 


*half-year
replace distance = 1
replace distance = 0 if abs_distance > 7

qui logit prom1 h2a $covars [iweight=distance] if (pos == 2), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table robust.xls", dec(4) 

qui logit prom1 ha0_36 ha38_47 hagt48 $covars [iweight=distance] if (pos == 2), robust
margins, dydx (h*) post
outreg2 h* using "$output/Table robust.xls", dec(4) 

qui logit prom1 h2u $covars [iweight=distance] if (pos == 2), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table robust.xls", dec(4) 

qui logit prom1 hu0_36 hu38_47 hugt48 $covars [iweight=distance] if (pos == 2), robust
margins, dydx (h*) post
outreg2 h* using "$output/Table robust.xls", dec(4) 


********************************************************************************
*	TABLE 6: Internal promotion and external recruit (Mlogit) 
********************************************************************************
use "$workdata\regression_data_full1", clear
global covars2 = "woman age age_sq exp exp_sq tenure tenure_sq kvu mvu lvu partner oldest* private"

logit prom1 h2a $covars if (pos == 2)
predict x if e(sample)
keep if x

keep if pos == 2

gen dest = .
replace dest = 0 if prom1 == 0 
replace dest = 1 if prom1 == 1 & new_workplace == 0 /* INDIVIDUALS WHO STAY */
replace dest = 2 if prom1 == 1 & new_workplace == 1 /* INDIVIDUALS WHO CHANGE FIRM */

preserve
qui mlogit dest h2a $covars2 if pos ==2, robust
predict sample_2 if e(sample)
est store m

est res m 
margins, dydx(h*) predict(outcome(0)) post
est store m0

est res m 
margins, dydx(h*) predict(outcome(1)) post
est store m1
outreg2 m1 using "$output/Table 6.xls", dec(4) 

est res m 
margins, dydx(h*) predict(outcome(2)) post
est store m2
outreg2 m2 using "$output/Table 6.xls", dec(4) 
restore

preserve
qui mlogit dest ha0_36 ha38_47 hagt48 $covars2 if pos ==2, robust
predict sample_2 if e(sample)
est store m

est res m 
margins, dydx(h*) predict(outcome(0)) post
est store m0

est res m 
margins, dydx(h*) predict(outcome(1)) post
est store m1
outreg2 m1 using "$output/Table 6.xls", dec(4) 

est res m 
margins, dydx(h*) predict(outcome(2)) post
est store m2
outreg2 m2 using "$output/Table 6.xls", dec(4) 
restore

preserve
qui mlogit dest h2u $covars2 if pos ==2, robust
predict sample_2 if e(sample)
est store m

est res m 
margins, dydx(h*) predict(outcome(0)) post
est store m0

est res m 
margins, dydx(h*) predict(outcome(1)) post
est store m1
outreg2 m1 using "$output/Table 6.xls", dec(4) 

est res m 
margins, dydx(h*) predict(outcome(2)) post
est store m2
outreg2 m2 using "$output/Table 6.xls", dec(4) 
restore


preserve
qui mlogit dest hu0_36 hu38_47 hugt48 $covars2 if pos ==2, robust
predict sample_2 if e(sample)
est store m

est res m 
margins, dydx(h*) predict(outcome(0)) post
est store m0

est res m 
margins, dydx(h*) predict(outcome(1)) post
est store m1
outreg2 m1 using "$output/Table 6.xls", dec(4) 

est res m 
margins, dydx(h*) predict(outcome(2)) post
est store m2
outreg2 m2 using "$output/Table 6.xls", dec(4) 
restore


************************************************************
*	TABLE 7: Top management appointments and longest hours
************************************************************
use "$workdata\regression_data_full1", clear
drop if pos >2

preserve
sort cvrnr year 
bys cvrnr year: egen max_h2=max(h2a)
gen max_guy = 0
replace max_guy = 1 if max_h2 == h2a
bys cvrnr year: gen workers=_N
drop if workers == 1

qui logit prom1 max_guy $covars if (pos == 2)
predict x if e(sample)

qui logit prom1 max_guy if (pos == 2) & x!=., robust
margins, dydx (max_guy) post
outreg2 max* using "$output/Table 7.xls", replace dec(4)

qui logit prom1 max_guy h2a if (pos == 2) & x!=., robust
margins, dydx (max_guy h*) post
outreg2 max* h* using "$output/Table 7.xls", dec(4) 

qui logit prom1 max_guy ha0_36 ha38_47 hagt48 if (pos == 2) & x!=., robust
margins, dydx (max_guy h*) post
outreg2 max* h* using "$output/Table 7.xls", dec(4)
restore

preserve
sort cvrnr year 
bys cvrnr year: egen max_h2=max(h2a)
gen max_guy = 0
replace max_guy = 1 if max_h2 == h2a
bys cvrnr year: gen workers=_N
drop if workers == 1

qui logit prom1 max_guy $covars if (pos == 2), robust
margins, dydx (max_guy) post
outreg2 max* using "$output/Table 7.xls", dec(4)

qui logit prom1 max_guy h2a $covars if (pos == 2), robust
margins, dydx (max_guy h*) post
outreg2 max* h* using "$output/Table 7.xls", dec(4)

qui logit prom1 max_guy ha0_36 ha38_47 hagt48 $covars if (pos == 2), robust
margins, dydx (max_guy h*) post
outreg2 max* h* using "$output/Table 7.xls", dec(4)
restore

*Usual
preserve
sort cvrnr year 
bys cvrnr year: egen max_h2=max(h2u)
gen max_guy = 0
replace max_guy = 1 if max_h2 == h2u
bys cvrnr year: gen workers=_N
drop if workers==1

qui logit prom1 max_guy $covars if (pos == 2)
predict x if e(sample)

qui logit prom1 max_guy if (pos == 2) & x!=., robust
margins, dydx (max_guy) post
outreg2 max* using "$output/Table 7.xls", dec(4)

qui logit prom1 max_guy h2u  if (pos == 2) & x!=., robust
margins, dydx (max_guy h*) post
outreg2 max* h* using "$output/Table 7.xls", dec(4)

qui logit prom1 max_guy hu0_36 hu38_47 hugt48 if (pos == 2) & x!=., robust
margins, dydx (max_guy h*) post
outreg2 max* h* using "$output/Table 7.xls", dec(4)
restore

*Usual
preserve
sort cvrnr year 
bys cvrnr year: egen max_h2=max(h2u)
gen max_guy = 0
replace max_guy = 1 if max_h2 == h2u
bys cvrnr year: gen workers=_N
drop if workers==1

qui logit prom1 max_guy $covars if (pos == 2), robust
margins, dydx (max_guy) post
outreg2 max* using "$output/Table 7.xls", dec(4)

qui logit prom1 max_guy h2u $covars if (pos == 2), robust
margins, dydx (max_guy h*) post
outreg2 max* h* using "$output/Table 7.xls", dec(4)

qui logit prom1 max_guy hu0_36 hu38_47 hugt48 $covars if (pos == 2), robust
margins, dydx (max_guy h*) post
outreg2 max* h* using "$output/Table 7.xls", dec(4) 
restore

********************************************************************************
*	Table 8: Top management appointments and nonstandard hours
********************************************************************************
use "$workdata\regression_data_full1", clear
drop if pos >2

qui logit prom1 d_frequent d_sometimes h2a $covars if (pos == 2), robust
test d_frequent = d_sometimes
margins, dydx (h* d_*) post
outreg2 d_* h* using "$output/Table 8.xls", replace dec(4) 

qui logit prom1 d_frequent d_sometimes ha0_36 ha38_47 hagt48 $covars if (pos == 2), robust
margins, dydx (h* d_*) post
test d_frequent = d_sometimes
outreg2 d_* h* using "$output/Table 8.xls", dec(4) 

qui logit prom1 d_frequent d_sometimes h2u $covars if (pos == 2), robust
margins, dydx (h* d_*) post
test d_frequent = d_sometimes
outreg2 d_* h* using "$output/Table 8.xls", dec(4) 

qui logit prom1 d_frequent d_sometimes hu0_36 hu38_47 hugt48 $covars if (pos == 2), robust
margins, dydx (h* d_*) post
test d_frequent = d_sometimes
outreg2 d_* h* using "$output/Table 8.xls", dec(4) 


********************************************************************************
*	Table 9: Top management appointments and sustained long hours
********************************************************************************
use "$workdata\hoursdata_1", clear
keep if h_actual >0 & h_actual !=.
keep if h_usual >0 & h_actual !=.
sort pnr aar refweek
by pnr: gen order = _n
gen yearweek = (aar - 1996) * 52 + refweek  				 //Weeks since year 1996
xtset pnr order
gen distanceF = F.yearweek - yearweek
gen distanceL =  yearweek - L.yearweek
keep if distanceF >= 12 & distanceF <=14 | distanceL >= 12 & distanceL <= 14   // keep if distance is 13 weeks +/- one week
keep if order <= 2   // keep only first and second observation for each individual
by pnr: gen obs = _N
keep if obs == 2 // keep only those with complete information i.e. h1 and h2
keep if order == 2  // keep only the second hours observation - to be merged with the large dataset
rename h_actual h_actual_13
rename h_usual h_usual_13
gen h2a_13 = h_actual_13/100
gen h2u_13 = h_usual_13/100
gen ha0_36_13 = ( h_actual_13 < 37 )
gen ha37_13 = ( h_actual_13 == 37 )
gen ha38_47_13 = ( h_actual_13>=38 & h_actual_13<=47 )
gen hagt48_13 = ( h_actual_13>=48 )
gen hu0_36_13 = ( h_usual_13 < 37 )
gen hu37_13 = ( h_usual_13 == 37 )
gen hu38_47_13 = ( h_usual_13>=38 & h_usual_13<=47 )
gen hugt48_13 = ( h_usual_13>=48 )
rename aar year_13
keep h2a* h2u* pnr year_13 ha* hu*
save "$workdata\hoursdata_1_M", replace

use "$workdata\regression_data_full1", clear
merge 1:1 pnr using "$workdata\hoursdata_1_M"
keep if _m == 3
keep if pos == 2
drop _m

qui logit prom1 h2a $covars if (pos == 2), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table 9.xls", dec(4) replace 

qui logit prom1 ha0_36 ha38_47 hagt48 $covars if (pos == 2), robust
margins, dydx (h*) post
outreg2 h* using "$output/Table 9.xls", dec(4) 

qui logit prom1 h2u  $covars if (pos == 2), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table 9.xls", dec(4) 

qui logit prom1 hu0_36 hu38_47 hugt48 $covars if (pos == 2), robust
margins, dydx (h*) post
outreg2 h* using "$output/Table 9.xls", dec(4) 

qui logit prom1 h2a h2a_13 $covars if (pos == 2), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table 9.xls", dec(4) 

qui logit prom1 ha0_36 ha38_47 hagt48 ha0_36_13 ha38_47_13 hagt48_13 $covars if (pos == 2), robust
margins, dydx (h*) post
outreg2 h* using "$output/Table 9.xls", dec(4) 

qui logit prom1 h2u h2u_13 $covars if (pos == 2), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table 9.xls", dec(4) 

qui logit prom1 hu0_36 hu38_47 hugt48 hu0_36_13 hu38_47_13 hugt48_13 $covars if (pos == 2), robust
margins, dydx (h*) post
outreg2 h* using "$output/Table 9.xls", dec(4) 

********************************************************************************
*	Table 10: Marginal Effects on FEMALE on top management appointments
********************************************************************************
use "$workdata\regression_data_full1", clear
drop if pos >2

bys woman: tab prom1

qui logit prom1 h2a $covars if (pos == 2), robust
predict base_a if e(sample)

*actual
global covars1w = "ib1996.year"
qui logit prom1 woman $covars1w if (pos == 2) & base_a !=. , robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) replace 

global covars1w = "ib1996.year"
qui logit prom1 woman h2a $covars1w if (pos == 2) & base_a !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

global covars1w = "ib1996.year"
qui logit prom1 woman h2a d_sometimes d_frequent $covars1w if (pos == 2) & base_a !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

global covars1w = "age age_sq exp exp_sq tenure tenure_sq ib1996.year"
qui logit prom1 woman h2a d_sometimes d_frequent $covars1w if (pos == 2) & base_a !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

global covars1w = "age age_sq exp exp_sq tenure tenure_sq kvu mvu lvu ib1996.year"
qui logit prom1 woman h2a d_sometimes d_frequent $covars1w if (pos == 2) & base_a !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

global covars1w = "age age_sq exp exp_sq tenure tenure_sq kvu mvu lvu partner ib1996.year"
qui logit prom1 woman h2a d_sometimes d_frequent $covars1w if (pos == 2) & base_a !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

global covars1w = "age age_sq exp exp_sq tenure tenure_sq kvu mvu lvu partner ib1996.year youngest*"
qui logit prom1 woman h2a d_sometimes d_frequent $covars1w if (pos == 2) & base_a !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

global covars1w = "age age_sq exp exp_sq tenure tenure_sq kvu mvu lvu partner ib1996.year youngest* export_pos sales firm_size"
qui logit prom1 woman h2a d_sometimes d_frequent $covars1w if (pos == 2) & base_a !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4)

global covars1w = "age age_sq exp exp_sq tenure tenure_sq kvu mvu lvu partner ib1996.year youngest* export_pos sales firm_size private i.industry"
qui logit prom1 woman h2a d_sometimes d_frequent $covars1w if (pos == 2) & base_a !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

global covars1w = "age age_sq exp exp_sq tenure tenure_sq kvu mvu lvu partner ib1996.year youngest* export_pos sales firm_size private i.industry i.disco2"
qui logit prom1 woman h2a d_sometimes d_frequent $covars1w if (pos == 2) & base_a !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

*usual
qui logit prom1 h2u $covars if (pos == 2), robust
predict base_u if e(sample)

global covars1w = "ib1996.year"
qui logit prom1 woman $covars1w if (pos == 2) & base_u !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

global covars1w = "ib1996.year"
qui logit prom1 woman h2u $covars1w if (pos == 2) & base_u !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

global covars1w = "ib1996.year"
qui logit prom1 woman h2u d_sometimes d_frequent $covars1w if (pos == 2) & base_u !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

global covars1w = "age age_sq exp exp_sq tenure tenure_sq ib1996.year"
qui logit prom1 woman h2u d_sometimes d_frequent $covars1w if (pos == 2) & base_u !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

global covars1w = "age age_sq exp exp_sq tenure tenure_sq kvu mvu lvu ib1996.year"
qui logit prom1 woman h2u d_sometimes d_frequent $covars1w if (pos == 2) & base_u !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

global covars1w = "age age_sq exp exp_sq tenure tenure_sq kvu mvu lvu partner ib1996.year"
qui logit prom1 woman h2u d_sometimes d_frequent $covars1w if (pos == 2) & base_u !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

global covars1w = "age age_sq exp exp_sq tenure tenure_sq kvu mvu lvu partner youngest* ib1996.year"
qui logit prom1 woman h2u d_sometimes d_frequent $covars1w if (pos == 2) & base_u !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

global covars1w = "age age_sq exp exp_sq tenure tenure_sq kvu mvu lvu partner youngest* ib1996.year export_pos sales firm_size"
qui logit prom1 woman h2u d_sometimes d_frequent $covars1w if (pos == 2) & base_u !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

global covars1w = "age age_sq exp exp_sq tenure tenure_sq kvu mvu lvu partner youngest* ib1996.year export_pos sales firm_size private i.industry"
qui logit prom1 woman h2u d_sometimes d_frequent $covars1w if (pos == 2) & base_u !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 

global covars1w = "age age_sq exp exp_sq tenure tenure_sq kvu mvu lvu partner youngest* ib1996.year export_pos sales firm_size private i.industry i.disco2"
qui logit prom1 woman h2u d_sometimes d_frequent $covars1w if (pos == 2) & base_u !=., robust
margins, dydx (woman) post
outreg2 woman using "$output/Table_10.xls", dec(4) 


*********************************************************************************************
*	Figure 1: Marginal effect of hours on top management appointments by industry and sector
*********************************************************************************************

use "$workdata\regression_data_full1", clear

preserve
logit prom1 h2a $covars if (pos == 2 & industry == 2), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table INDU.xls", dec(4) replace
display _b[h2a]
gen b_industry = _b[h2a]
sum woman if (pos == 2 & industry == 2)
display r(mean)
gen avr_woman = r(mean)
keep if (pos == 2 & industry == 2)
keep if _n == 1
keep industry avr_woman b_industry
sum
save "$workdata\data_industry_2", replace 
restore

preserve
logit prom1 h2a $covars if (pos == 2 & industry == 8), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table INDU.xls", dec(4) 
display _b[h2a]
gen b_industry = _b[h2a]
sum woman if (pos == 2 & industry == 8)
display r(mean)
gen avr_woman = r(mean)
keep if (pos == 2 & industry == 8)
keep if _n == 1
keep industry avr_woman b_industry
sum
save "$workdata\data_industry_8", replace 
restore

preserve
logit prom1 h2a $covars if (pos == 2 & industry == 9), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table INDU.xls", dec(4) 
display _b[h2a]
gen b_industry = _b[h2a]
sum woman if (pos == 2 & industry == 9)
display r(mean)
gen avr_woman = r(mean)
keep if (pos == 2 & industry == 9)
keep if _n == 1
keep industry avr_woman b_industry
sum
save "$workdata\data_industry_9", replace 
restore

preserve
logit prom1 h2a $covars if (pos == 2 & industry == 10), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table INDU.xls", dec(4) 
display _b[h2a]
gen b_industry = _b[h2a]
sum woman if (pos == 2 & industry == 10)
display r(mean)
gen avr_woman = r(mean)
keep if (pos == 2 & industry == 10)
keep if _n == 1
keep industry avr_woman b_industry
sum
save "$workdata\data_industry_10", replace 
restore

preserve
logit prom1 h2a $covars if (pos == 2 & industry == 11), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table INDU.xls", dec(4) 
display _b[h2a]
gen b_industry = _b[h2a]
sum woman if (pos == 2 & industry == 11)
display r(mean)
gen avr_woman = r(mean)
keep if (pos == 2 & industry == 11)
keep if _n == 1
keep industry avr_woman b_industry
sum
save "$workdata\data_industry_11", replace 
restore

preserve
logit prom1 h2a $covars if (pos == 2 & industry == 12), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table INDU.xls", dec(4) 
display _b[h2a]
gen b_industry = _b[h2a]
sum woman if (pos == 2 & industry == 12)
display r(mean)
gen avr_woman = r(mean)
keep if (pos == 2 & industry == 12)
keep if _n == 1
keep industry avr_woman b_industry
sum
save "$workdata\data_industry_12", replace 
restore

preserve
logit prom1 h2a $covars if (pos == 2 & private == 0), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table INDU.xls", dec(4) 
display _b[h2a]
gen b_industry = _b[h2a]
sum woman if (pos == 2 & private == 0)
display r(mean)
gen avr_woman = r(mean)
keep if (pos == 2 & private == 0)
keep if _n == 1
replace industry = 100
keep industry avr_woman b_industry
sum
save "$workdata\data_industry_100", replace 
restore

preserve
logit prom1 h2a $covars if (pos == 2 & private == 1), robust
margins, dydx (h*) post 
outreg2 h* using "$output/Table INDU.xls", dec(4) 
display _b[h2a]
gen b_industry = _b[h2a]
sum woman if (pos == 2 & private == 1)
display r(mean)
gen avr_woman = r(mean)
keep if (pos == 2 & private == 1)
keep if _n == 1
replace industry = 101
keep industry avr_woman b_industry
sum
save "$workdata\data_industry_101", replace 
restore

use "$workdata\data_industry_2", clear
append using "$workdata\data_industry_8"
append using "$workdata\data_industry_9"
append using "$workdata\data_industry_10"
append using "$workdata\data_industry_11"
append using "$workdata\data_industry_12"
append using "$workdata\data_industry_100"
append using "$workdata\data_industry_101"

gen pp = .
replace pp = 1 if industry == 100 | industry == 101

gen name_industry = ""
replace name_industry = "Public sector" if industry == 100
replace name_industry = "Private sector" if industry == 101
replace name_industry = "Industry" if industry == 2
replace name_industry = "Finance" if industry == 8
replace name_industry = "Real estate" if industry == 9
replace name_industry = "Public administration" if industry == 10
replace name_industry = "Education" if industry == 11
replace name_industry = "Health care" if industry == 12

gen pos = 3
replace pos = 6 if industry == 100
replace pos = 3 if industry == 101
replace pos = 3 if industry == 9
replace pos = 12 if industry == 11
replace pos = 9 if industry == 12


twoway scatter b_industry avr_woman if pp == ., yline(0.0229) mlabel(name_industry) mlabv(pos) || scatter b_industry avr_woman if pp == 1, msymbol(D) mlabel(name_industry) mlabv(pos) ///
xtitle("Proportion of women") ytitle("Marginal effect") legend(off) ///
note("Note: Horizontal line is the marginal effect for actual hours presented in Table 4")


********************************************************************************
*	Figure 2: Hours-Career Profiles: Men vs. Women
********************************************************************************

*Men
*H_actual
use "$workdata\regression_data_full1", clear
keep if woman == 0

keep if pos == 2
reg prom1 $covars 
predict res_1 if e(sample), res
keep res_1 h_actual
save "$workdata\test_M", replace

forvalues i = 1/100 {
use "$workdata\test_M", clear
bsample
lowess res_1 h_actual, gen(gr_res) nogr
keep if gr_res !=.
bys h_actual: gen xx = _n 
keep if xx == 1
drop if h_actual < 30
keep h_actual gr_res
save "$workdata\gr_res_`i'_M", replace
}

use "$workdata\gr_res_1_M", clear
forvalues i = 2/100 {
append using "$workdata\gr_res_`i'_M"
}

bys h_actual: egen avr_effect_a = mean(gr_res)
bys h_actual: egen sd_effect_a = sd(gr_res)

gen upper_a = avr_effect+1.645*sd_effect
gen lower_a = avr_effect-1.645*sd_effect

bys h_actual: gen xx = _n
keep if xx == 1
drop xx

rename h_actual h

drop gr_res sd 
sort h
save "$workdata\CI_a_M", replace


*H_usual
use "$workdata\regression_data_full1", clear
keep if woman == 0

keep if pos == 2
reg prom1 $covars 
predict res_1 if e(sample), res
keep res_1 h_usual
save "$workdata\test_u_M", replace

forvalues i = 1/100 {
use "$workdata\test_u_M", clear
bsample
lowess res_1 h_usual, gen(gr_res) nogr
keep if gr_res !=.
bys h_usual: gen xx = _n 
keep if xx == 1
drop if h_usual < 30
keep h_usual gr_res
save "$workdata\gr_res_`i'_u_M", replace
}

use "$workdata\gr_res_1_u_M", clear
forvalues i = 2/100 {
append using "$workdata\gr_res_`i'_u_M"
}

bys h_usual: egen avr_effect_u = mean(gr_res)
bys h_usual: egen sd_effect_u = sd(gr_res)

gen upper_u = avr_effect+1.645*sd_effect
gen lower_u = avr_effect-1.645*sd_effect

bys h_usual: gen xx = _n
keep if xx == 1
drop xx

rename h_usual h

drop gr_res sd
sort h
save "$workdata\CI_u_M", replace

use "$workdata\CI_a_M", clear
merge h using "$workdata\CI_u_M"
drop _m

drop if h >60 

line avr_effect_a h, lcolor(black) || line avr_effect_u h, lcolor(black) lpattern("__") || line upper_a h, lcolor(black) lpattern("..") || line upper_u h, lcolor(black) lpattern("..###..") /// 
|| line lower_a h, lcolor(black) lpattern("..") || line lower_u h, lcolor(black) lpattern("..###..") ylabel(-0.01(0.005)0.02) xtitle("Hours") ytitle("Appointment (Residual)") legend(label(1 "Actual hours")  ///
label(2 "Usual hours") label(3 "Upper 90% CI actual") label(4 "Upper 90% CI usual") label(5 "Lower 90% CI actual") label(6 "Lower 90% CI usual")) title("Men")



*Women
*H_actual
use "$workdata\regression_data_full1", clear
keep if woman == 1
keep if pos == 2
reg prom1 $covars 
predict res_1 if e(sample), res
keep res_1 h_actual
save "$workdata\test_W", replace

forvalues i = 1/100 {
use "$workdata\test_W", clear
bsample
lowess res_1 h_actual, gen(gr_res) nogr
keep if gr_res !=.
bys h_actual: gen xx = _n 
keep if xx == 1
drop if h_actual < 30
keep h_actual gr_res
save "$workdata\gr_res_`i'_W", replace
}

use "$workdata\gr_res_1_W", clear
forvalues i = 2/100 {
append using "$workdata\gr_res_`i'_W"
}

bys h_actual: egen avr_effect_a = mean(gr_res)
bys h_actual: egen sd_effect_a = sd(gr_res)

gen upper_a = avr_effect+1.645*sd_effect
gen lower_a = avr_effect-1.645*sd_effect

bys h_actual: gen xx = _n
keep if xx == 1
drop xx

rename h_actual h

drop gr_res sd 
sort h
save "$workdata\CI_a_W", replace


*H_usual
use "$workdata\regression_data_full1", clear
keep if woman == 1
keep if pos == 2
reg prom1 $covars 
predict res_1 if e(sample), res
keep res_1 h_usual
save "$workdata\test_u_W", replace

forvalues i = 1/100 {
use "$workdata\test_u_W", clear
bsample
lowess res_1 h_usual, gen(gr_res) nogr
keep if gr_res !=.
bys h_usual: gen xx = _n 
keep if xx == 1
drop if h_usual < 30
keep h_usual gr_res
save "$workdata\gr_res_`i'_u_W", replace
}

use "$workdata\gr_res_1_u_W", clear
forvalues i = 2/100 {
append using "$workdata\gr_res_`i'_u_W"
}

bys h_usual: egen avr_effect_u = mean(gr_res)
bys h_usual: egen sd_effect_u = sd(gr_res)

gen upper_u = avr_effect+1.645*sd_effect
gen lower_u = avr_effect-1.645*sd_effect

bys h_usual: gen xx = _n
keep if xx == 1
drop xx

rename h_usual h

drop gr_res sd
sort h
save "$workdata\CI_u_W", replace

use "$workdata\CI_a_W", clear
merge h using "$workdata\CI_u_W"
drop _m
sum

drop if h >60 

line avr_effect_a h, lcolor(black) || line avr_effect_u h, lcolor(black) lpattern("__") || line upper_a h, lcolor(black) lpattern("..") || line upper_u h, lcolor(black) lpattern("..##..") /// 
|| line lower_a h, lcolor(black) lpattern("..") || line lower_u h, lcolor(black) lpattern("..##..") ylabel(-0.01(0.005)0.02) xtitle("Hours") ytitle("Appointment (Residual)") legend(label(1 "Actual hours")  ///
label(2 "Usual hours") label(3 "Upper 90% CI actual") label(4 "Upper 90% CI usual") label(5 "Lower 90% CI actual") label(6 "Lower 90% CI usual")) title("Women")


********************************************************************************
*	Table A1
********************************************************************************

use "$workdata\regression_data_full1", clear
keep if pos == 2

*Baseline
qui logit prom1 h2a $covars if (pos == 2), robust
margins, dydx (h* woman) post 
outreg2 h* woman using "$output/Table A1.xls", dec(4) replace 

qui logit prom1 ha0_36 ha38_47 hagt48 $covars if (pos == 2), robust
margins, dydx (h* woman) post
outreg2 h* woman using "$output/Table A1.xls", dec(4) 

qui logit prom1 h2u $covars if (pos == 2), robust
margins, dydx (h* woman) post 
outreg2 h* woman using "$output/Table A1.xls", dec(4) 

qui logit prom1 hu0_36 hu38_47 hugt48 $covars if (pos == 2), robust
margins, dydx (h* woman) post
outreg2 h* woman using "$output/Table A1.xls", dec(4) 

*Interactions
gen int_h2a_woman = h2a*woman
gen int_ha0_36_woman = ha0_36*woman
gen int_ha38_47_woman = ha38_47*woman
gen int_hagt48_woman = hagt48*woman

gen int_h2u_woman = h2u*woman
gen int_hu0_36_woman = hu0_36*woman
gen int_hu38_47_woman = hu38_47*woman
gen int_hugt48_woman = hugt48*woman

qui logit prom1 h2a int_h2a $covars if (pos == 2), robust
margins, dydx (h* woman int*) post 
outreg2 h* woman int* using "$output/Table A1.xls", dec(4) 

qui logit prom1 ha0_36 ha38_47 hagt48 int_ha* $covars if (pos == 2), robust
margins, dydx (h* woman int*) post
outreg2 h* woman int* using "$output/Table A1.xls", dec(4) 

qui logit prom1 h2u int_h2u $covars if (pos == 2), robust
margins, dydx (h* woman int*) post 
outreg2 h* woman int* using "$output/Table A1.xls", dec(4) 

qui logit prom1 hu0_36 hu38_47 hugt48 int_hu* $covars if (pos == 2), robust
margins, dydx (h* woman int*) post
outreg2 h* woman int* using "$output/Table A1.xls", dec(4) 


********************************************************************************
*	Table A2
********************************************************************************

use "$workdata\regression_data_full1", clear
keep if pos == 2

*Baseline
qui logit prom1 h2a $covars if (pos == 2), robust
margins, dydx (h* woman) post 
outreg2 h* woman using "$output/Table A2.xls", dec(4) replace

qui logit prom1 ha0_36 ha38_47 hagt48 $covars if (pos == 2), robust
margins, dydx (h* woman) post
outreg2 h* woman using "$output/Table A2.xls", dec(4) 

qui logit prom1 h2u $covars if (pos == 2), robust
margins, dydx (h* woman) post 
outreg2 h* woman using "$output/Table A2.xls", dec(4) 

qui logit prom1 hu0_36 hu38_47 hugt48 $covars if (pos == 2), robust
margins, dydx (h* woman ) post
outreg2 h* woman using "$output/Table A2.xls", dec(4) 

qui logit prom1 d_frequent d_sometimes h2a $covars if (pos == 2), robust
margins, dydx (h* woman d_*) post 
outreg2 h* woman using "$output/Table A2.xls", dec(4) replace

qui logit prom1 d_frequent d_sometimes ha0_36 ha38_47 hagt48 $covars if (pos == 2), robust
margins, dydx (h* woman d_*) post
outreg2 h* woman using "$output/Table A2.xls", dec(4) 

qui logit prom1 d_frequent d_sometimes h2u $covars if (pos == 2), robust
margins, dydx (h* woman d_*) post 
outreg2 h* woman using "$output/Table A2.xls", dec(4) 

qui logit prom1 d_frequent d_sometimes hu0_36 hu38_47 hugt48 $covars if (pos == 2), robust
margins, dydx (h* woman d_*) post
outreg2 h* woman using "$output/Table A2.xls", dec(4) 

*Interactions
gen int_h2a_woman = h2a*woman
gen int_ha0_36_woman = ha0_36*woman
gen int_ha38_47_woman = ha38_47*woman
gen int_hagt48_woman = hagt48*woman

qui logit prom1 h2a int_h2* $covars if (pos == 2), robust
margins, dydx (h* woman int*) post 
outreg2 h* woman int* using "$output/Table A2.xls", dec(4) 

qui logit prom1 ha0_36 ha38_47 hagt48 int_ha* $covars if (pos == 2), robust
margins, dydx (h* woman int*) post
outreg2 h* woman int* using "$output/Table A2.xls", dec(4) 

gen int_d_frequent_woman = d_frequent*woman
gen int_d_sometimes_woman = d_sometimes*woman

qui logit prom1 h2a d_frequent d_sometimes int_h2* int_d* $covars if (pos == 2), robust
margins, dydx (h* woman int*  d_frequent d_sometimes) post 
outreg2 h* woman int* using "$output/Table A2.xls", dec(4) 

qui logit prom1 ha0_36 ha38_47 hagt48 d_frequent d_sometimes int_ha* int_d* $covars if (pos == 2), robust
margins, dydx (h* woman int*  d_frequent d_sometimes) post
outreg2 h* woman int* using "$output/Table A2.xls", dec(4) 

drop int*

gen int_h2u_woman = h2u*woman
gen int_hu0_36_woman = hu0_36*woman
gen int_hu38_47_woman = hu38_47*woman
gen int_hugt48_woman = hugt48*woman

qui logit prom1 h2u int_h2* $covars if (pos == 2), robust
margins, dydx (h* woman int*) post 
outreg2 h* woman int* using "$output/Table A2.xls", dec(4) 

qui logit prom1 hu0_36 hu38_47 hugt48 int_hu* $covars if (pos == 2), robust
margins, dydx (h* woman int*) post
outreg2 h* woman int* using "$output/Table A2.xls", dec(4) 

gen int_d_frequent_woman = d_frequent*woman
gen int_d_sometimes_woman = d_sometimes*woman

qui logit prom1 h2u d_frequent d_sometimes int_h2* int_d* $covars if (pos == 2), robust
margins, dydx (h* woman int*  d_frequent d_sometimes) post 
outreg2 h* woman int* using "$output/Table A2.xls", dec(4) 

qui logit prom1 hu0_36 hu38_47 hugt48 d_frequent d_sometimes int_hu* int_d* $covars if (pos == 2), robust
margins, dydx (h* woman int*  d_frequent d_sometimes) post
outreg2 h* woman int* using "$output/Table A2.xls", dec(4) 

********************************************************************************
*	Table A3
********************************************************************************
use "$workdata\regression_data_full1", clear

keep if pos == 3
drop prom1
gen prom1 = (pos == 3 & leadpos <= 2)

*Baseline
qui logit prom1 h2a $covars, robust
margins, dydx (h* woman) post 
outreg2 h* woman using "$output/Table A3.xls", dec(4) replace

qui logit prom1 ha0_36 ha38_47 hagt48 $covars, robust
margins, dydx (h* woman) post
outreg2 h* woman using "$output/Table A3.xls", dec(4) 

qui logit prom1 h2u $covars, robust
margins, dydx (h* woman) post 
outreg2 h* woman using "$output/Table A3.xls", dec(4) 

qui logit prom1 hu0_36 hu38_47 hugt48 $covars, robust
margins, dydx (h* woman) post
outreg2 h* woman using "$output/Table A3.xls", dec(4) 


*Interactions
gen int_h2a_woman = h2a*woman
gen int_ha0_36_woman = ha0_36*woman
gen int_ha38_47_woman = ha38_47*woman
gen int_hagt48_woman = hagt48*woman

gen int_h2u_woman = h2u*woman
gen int_hu0_36_woman = hu0_36*woman
gen int_hu38_47_woman = hu38_47*woman
gen int_hugt48_woman = hugt48*woman

qui logit prom1 h2a int_h2a $covars, robust
margins, dydx (h* woman int*) post 
outreg2 h* woman int* using "$output/Table A3.xls", dec(4) 

qui logit prom1 ha0_36 ha38_47 hagt48 int_ha* $covars, robust
margins, dydx (h* woman int*) post
outreg2 h* woman int* using "$output/Table A3.xls", dec(4) 

qui logit prom1 h2u int_h2u $covars, robust
margins, dydx (h* woman int*) post 
outreg2 h* woman int* using "$output/Table A3.xls", dec(4) 

qui logit prom1 hu0_36 hu38_47 hugt48 int_hu* $covars, robust
margins, dydx (h* woman int*) post
outreg2 h* woman int* using "$output/Table A3.xls", dec(4) 


********************************************************************************
*	Table A4
********************************************************************************
use "$workdata\regression_data_full1", clear

keep if pos == 3
drop prom1
gen prom1 = (pos == 3 & leadpos <= 2)

*Baseline
qui logit prom1 d_frequent d_sometimes h2a $covars , robust
margins, dydx (h* woman d_*) post 
outreg2 h* woman using "$output/Table A4.xls", dec(4) replace

qui logit prom1 d_frequent d_sometimes ha0_36 ha38_47 hagt48 $covars , robust
margins, dydx (h* woman d_*) post
outreg2 h* woman using "$output/Table A4.xls", dec(4) 

qui logit prom1 d_frequent d_sometimes h2u $covars , robust
margins, dydx (h* woman d_*) post 
outreg2 h* woman using "$output/Table A4.xls", dec(4) 

qui logit prom1 d_frequent d_sometimes hu0_36 hu38_47 hugt48 $covars , robust
margins, dydx (h* woman d_*) post
outreg2 h* woman using "$output/Table A4.xls", dec(4) 

*Interactions
gen int_d_frequent_woman = d_frequent*woman
gen int_d_sometimes_woman = d_sometimes*woman

qui logit prom1 h2a d_frequent d_sometimes int_h2a* int_d* $covars, robust
margins, dydx (h* woman int*  d_frequent d_sometimes) post 
outreg2 h* woman int* using "$output/Table A4.xls", dec(4) 

qui logit prom1 ha0_36 ha38_47 hagt48 d_frequent d_sometimes int_ha* int_d* $covars, robust
margins, dydx (h* woman int*  d_frequent d_sometimes) post
outreg2 h* woman int* using "$output/Table A4.xls", dec(4) 

qui logit prom1 h2u d_frequent d_sometimes int_h2u* int_d* $covars, robust
margins, dydx (h* woman int*  d_frequent d_sometimes) post 
outreg2 h* woman int* using "$output/Table A4.xls", dec(4) 

qui logit prom1 hu0_36 hu38_47 hugt48 d_frequent d_sometimes int_hu* int_d* $covars, robust
margins, dydx (h* woman int*  d_frequent d_sometimes) post
outreg2 h* woman int* using "$output/Table A4.xls", dec(4) 
